home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 21 / AACD 21.iso / AACD / Utilities / Ghostscript / src / gsptype2.c < prev    next >
Encoding:
C/C++ Source or Header  |  2001-01-01  |  6.5 KB  |  197 lines

  1. /* Copyright (C) 1999 Aladdin Enterprises.  All rights reserved.
  2.   
  3.   This file is part of AFPL Ghostscript.
  4.   
  5.   AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND.  No author or
  6.   distributor accepts any responsibility for the consequences of using it, or
  7.   for whether it serves any particular purpose or works at all, unless he or
  8.   she says so in writing.  Refer to the Aladdin Free Public License (the
  9.   "License") for full details.
  10.   
  11.   Every copy of AFPL Ghostscript must include a copy of the License, normally
  12.   in a plain ASCII text file named PUBLIC.  The License grants you the right
  13.   to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14.   conditions described in the License.  Among other things, the License
  15.   requires that the copyright notice and this notice be preserved on all
  16.   copies.
  17. */
  18.  
  19. /*$Id: gsptype2.c,v 1.3.2.1 2000/11/29 01:29:50 raph Exp $ */
  20. /* PatternType 2 implementation */
  21. #include "gx.h"
  22. #include "gscspace.h"
  23. #include "gsshade.h"
  24. #include "gsmatrix.h"        /* for gspcolor.h */
  25. #include "gsstate.h"        /* for set/currentfilladjust */
  26. #include "gxcolor2.h"
  27. #include "gxdcolor.h"
  28. #include "gsptype2.h"
  29. #include "gxpcolor.h"
  30. #include "gxstate.h"        /* for gs_state_memory */
  31. #include "gzpath.h"
  32.  
  33. /* GC descriptors */
  34. private_st_pattern2_template();
  35. private_st_pattern2_instance();
  36.  
  37. /* GC procedures */
  38. private ENUM_PTRS_BEGIN(pattern2_instance_enum_ptrs) {
  39.     if (index < st_pattern2_template_max_ptrs) {
  40.     gs_ptr_type_t ptype =
  41.         ENUM_SUPER_ELT(gs_pattern2_instance_t, st_pattern2_template,
  42.                template, 0);
  43.  
  44.     if (ptype)
  45.         return ptype;
  46.     return ENUM_OBJ(NULL);    /* don't stop early */
  47.     }
  48.     ENUM_PREFIX(st_pattern_instance, st_pattern2_template_max_ptrs);
  49. }
  50. ENUM_PTRS_END
  51. private RELOC_PTRS_BEGIN(pattern2_instance_reloc_ptrs) {
  52.     RELOC_PREFIX(st_pattern_instance);
  53.     RELOC_SUPER(gs_pattern2_instance_t, st_pattern2_template, template);
  54. } RELOC_PTRS_END
  55.  
  56. /* Define a PatternType 2 pattern. */
  57. private pattern_proc_uses_base_space(gs_pattern2_uses_base_space);
  58. private pattern_proc_make_pattern(gs_pattern2_make_pattern);
  59. private pattern_proc_get_pattern(gs_pattern2_get_pattern);
  60. private pattern_proc_remap_color(gs_pattern2_remap_color);
  61. private const gs_pattern_type_t gs_pattern2_type = {
  62.     2, {
  63.     gs_pattern2_uses_base_space, gs_pattern2_make_pattern,
  64.     gs_pattern2_get_pattern, gs_pattern2_remap_color
  65.     }
  66. };
  67.  
  68. /* Initialize a PatternType 2 pattern. */
  69. void
  70. gs_pattern2_init(gs_pattern2_template_t * ppat)
  71. {
  72.     gs_pattern_common_init((gs_pattern_template_t *)ppat, &gs_pattern2_type);
  73. }
  74.  
  75. /* Test whether a PatternType 2 pattern uses a base space. */
  76. private bool
  77. gs_pattern2_uses_base_space(const gs_pattern_template_t *ptemp)
  78. {
  79.     return false;
  80. }
  81.  
  82. /* Make an instance of a PatternType 2 pattern. */
  83. private int
  84. gs_pattern2_make_pattern(gs_client_color * pcc,
  85.              const gs_pattern_template_t * pcp,
  86.              const gs_matrix * pmat, gs_state * pgs,
  87.              gs_memory_t * mem)
  88. {
  89.     const gs_pattern2_template_t *ptemp =
  90.     (const gs_pattern2_template_t *)pcp;
  91.     int code = gs_make_pattern_common(pcc, pcp, pmat, pgs, mem,
  92.                       &st_pattern2_instance);
  93.     gs_pattern2_instance_t *pinst;
  94.  
  95.     if (code < 0)
  96.     return code;
  97.     pinst = (gs_pattern2_instance_t *)pcc->pattern;
  98.     pinst->template = *ptemp;
  99.     return 0;
  100. }
  101.  
  102. /* Get the template of a PatternType 2 pattern instance. */
  103. private const gs_pattern_template_t *
  104. gs_pattern2_get_pattern(const gs_pattern_instance_t *pinst)
  105. {
  106.     return (const gs_pattern_template_t *)
  107.     &((const gs_pattern2_instance_t *)pinst)->template;
  108. }
  109.  
  110. /* ---------------- Rendering ---------------- */
  111.  
  112. /* GC descriptor */
  113. gs_private_st_ptrs_add0(st_dc_pattern2, gx_device_color, "dc_pattern2",
  114.             dc_pattern2_enum_ptrs, dc_pattern2_reloc_ptrs,
  115.             st_client_color, ccolor);
  116.  
  117. private dev_color_proc_load(gx_dc_pattern2_load);
  118. private dev_color_proc_fill_rectangle(gx_dc_pattern2_fill_rectangle);
  119. private dev_color_proc_equal(gx_dc_pattern2_equal);
  120. /*
  121.  * Define the PatternType 2 Pattern device color type.  This is public only
  122.  * for testing when writing PDF or PostScript.
  123.  */
  124. const gx_device_color_type_t gx_dc_pattern2 = {
  125.     &st_dc_pattern2,
  126.     gx_dc_pattern2_load, gx_dc_pattern2_fill_rectangle,
  127.     gx_dc_default_fill_masked, gx_dc_pattern2_equal
  128. };
  129.  
  130. /* Load a PatternType 2 color into the cache.  (No effect.) */
  131. private int
  132. gx_dc_pattern2_load(gx_device_color *pdevc, const gs_imager_state *ignore_pis,
  133.             gx_device *ignore_dev, gs_color_select_t ignore_select)
  134. {
  135.     return 0;
  136. }
  137.  
  138. /* Remap a PatternType 2 color. */
  139. private int
  140. gs_pattern2_remap_color(const gs_client_color * pc, const gs_color_space * pcs,
  141.             gx_device_color * pdc, const gs_imager_state * pis,
  142.             gx_device * dev, gs_color_select_t select)
  143. {
  144.     /* We don't do any actual color mapping now. */
  145.     pdc->type = &gx_dc_pattern2;
  146.     pdc->ccolor = *pc;
  147.     return 0;
  148. }
  149.  
  150. /* Fill a rectangle with a PatternType 2 color.  Glacially slow! */
  151. private int
  152. gx_dc_pattern2_fill_rectangle(const gx_device_color * pdevc, int x, int y,
  153.                   int w, int h, gx_device * dev,
  154.                   gs_logical_operation_t lop,
  155.                   const gx_rop_source_t * source)
  156. {
  157.     gs_pattern2_instance_t *pinst =
  158.     (gs_pattern2_instance_t *)pdevc->ccolor.pattern;
  159.     gs_state *pgs = pinst->saved;
  160.     gs_fixed_rect rect;
  161.     gs_point save_adjust;
  162.     int code;
  163.  
  164.     rect.p.x = int2fixed(x);
  165.     rect.p.y = int2fixed(y);
  166.     rect.q.x = int2fixed(x + w);
  167.     rect.q.y = int2fixed(y + h);
  168.     /* We don't want any adjustment of the box. */
  169.     gs_currentfilladjust(pgs, &save_adjust);
  170.  
  171.     /*
  172.      * We should set the fill adjustment to zero here, so that we don't
  173.      * get multiply-written pixels as a result of filling abutting
  174.      * triangles.  However, numerical inaccuracies in the shading
  175.      * algorithms can cause pixel dropouts, and a non-zero adjustment
  176.      * is by far the easiest way to work around them as a stopgap.
  177.      * NOTE: This makes shadings not interact properly with
  178.      * non-idempotent RasterOps (not a problem in practice, since
  179.      * PostScript doesn't have RasterOps and PCL doesn't have shadings).
  180.      */
  181.     gs_setfilladjust(pgs, 0.5, 0.5);
  182.     /****** DOESN'T HANDLE RASTER OP ******/
  183.     code = gs_shading_fill_path(pinst->template.Shading, NULL, &rect, dev,
  184.                 (gs_imager_state *)pgs, true);
  185.     gs_setfilladjust(pgs, save_adjust.x, save_adjust.y);
  186.     return code;
  187. }
  188.  
  189. /* Compare two PatternType 2 colors for equality. */
  190. private bool
  191. gx_dc_pattern2_equal(const gx_device_color * pdevc1,
  192.              const gx_device_color * pdevc2)
  193. {
  194.     return pdevc2->type == pdevc1->type &&
  195.     pdevc1->ccolor.pattern == pdevc2->ccolor.pattern;
  196. }
  197.